use "datapath/MSCI_exceldata_to_DTA.dta", clear // total return index, earning-price, dividend-price

* keep total return index to compute equity returns
keep datem country usdreturn
drop if mi(usdreturn)

*****************************************************************************
* forward returns
global rforwardhorizon = "1 12 24 36"
foreach hor of global rforwardhorizon {
	bys country (datem) : gen r`hor' = (usdreturn[_n+`hor'] - usdreturn)/usdreturn // undiscounted forward return
}
*****************************************************************************

*****************************************************************************
* contemporaneous return
bys country (datem) : gen r = (usdreturn - usdreturn[_n-1])/usdreturn[_n-1]
*****************************************************************************

*****************************************************************************
* Discounted returns - benchmark
global discount = "89 90 92 925 93 94"
foreach disc of global discount {
	forvalues j = 1 /60 {
		local k = `j'- 1
		bys country (datem) :  gen rd`disc'_`j' = ((0.`disc')^`k')*(usdreturn[_n+`j'] - usdreturn[_n+`k'])/usdreturn[_n+`k']
	}
}
*****************************************************************************

*****************************************************************************
* cumulated discounted returns
foreach disc of global discount {
	qui gen r12d`disc' = rd`disc'_1+rd`disc'_2+rd`disc'_3+rd`disc'_4+rd`disc'_5+rd`disc'_6+rd`disc'_7+rd`disc'_8+rd`disc'_9+rd`disc'_10+rd`disc'_11+rd`disc'_12
	qui gen r24d`disc' = rd`disc'_1+rd`disc'_2+rd`disc'_3+rd`disc'_4+rd`disc'_5+rd`disc'_6+rd`disc'_7+rd`disc'_8+rd`disc'_9+rd`disc'_10+rd`disc'_11+rd`disc'_12+rd`disc'_13+rd`disc'_14+rd`disc'_15+rd`disc'_16+rd`disc'_17+rd`disc'_18+rd`disc'_19+rd`disc'_20+rd`disc'_21+rd`disc'_22+rd`disc'_23+rd`disc'_24	
	qui gen r36d`disc' = rd`disc'_1+rd`disc'_2+rd`disc'_3+rd`disc'_4+rd`disc'_5+rd`disc'_6+rd`disc'_7+rd`disc'_8+rd`disc'_9+rd`disc'_10+rd`disc'_11+rd`disc'_12+rd`disc'_13+rd`disc'_14+rd`disc'_15+rd`disc'_16+rd`disc'_17+rd`disc'_18+rd`disc'_19+rd`disc'_20+rd`disc'_21+rd`disc'_22+rd`disc'_23+rd`disc'_24+rd`disc'_25+rd`disc'_26+rd`disc'_27+rd`disc'_28+rd`disc'_29+rd`disc'_30+rd`disc'_31+rd`disc'_32+rd`disc'_33+rd`disc'_34+rd`disc'_35+rd`disc'_36
}
* keep relevant return horizons
keep datem country r r1 r12 r36 r12d90 r36d93 r24 r24d89 r24d90 r24d92 r24d925 r24d93 r24d94 r36d90 
*****************************************************************************

save "$datapath/Prediction_DiscountedReturns.dta", replace
* end
*****************************************************************************